<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017-10-05
 * Time: 22:47
 */

namespace app\Http\Controllers\Wechat;


use App\Http\Controllers\Controller;
use App\Models\WechatUpload;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;

class MyVideoController extends Controller
{
    public function getIndex()
    {
        return view('wechat.my-video');
    }

    public function postIndex(Request $request)
    {
        $wechatUploads = WechatUpload::query()
            ->where('openid', Session::get('wechat_openid'))
            ->where('type', 2)
            ->where('status', 0)
            ->orderBy('id', 'desc')
            ->paginate(20);
        $result['data'] = [];
        foreach ($wechatUploads as $wechatUpload) {
            $result['data'][] = [
                'id' => $wechatUpload->id,
                'uniacid' => '10',
                'openid' => $wechatUpload->openid,
                'origin_openid' => $wechatUpload->openid,
                'title' => $wechatUpload->title,
                'url' => '/wechat/view?id=' . $wechatUpload->id,
                'price' => (string) $wechatUpload->price,
                'up' => (string) $wechatUpload->up,
                'down' => (string) $wechatUpload->down,
                'status' => '1',
                'review' => (string) $wechatUpload->buy_count,
                'qiniu_stat' => '1',
                'create_time' => strtotime($wechatUpload->created_at),
                'show_times' => (string) $wechatUpload->buy_count,
                'icon' => $wechatUpload->guest_image . '?imageView2/1/w/64/h/64',
            ];
        }
        $result['next_page'] = next_page($wechatUploads, $request);
        return response()->json($result);
    }
}